package com.tmp.util;

import org.apache.commons.lang.StringUtils;

public class PvoUtil {
	
	/**
	 * 根据表明获取实体名
	 * @param tableName
	 */
	public static String getEntityNameByTableName(String tableName) {
		if(StringUtils.isEmpty(tableName)) {
			return tableName;
		}
		tableName = tableName.trim().toLowerCase();
		String[] arr = StringUtils.split(tableName, "_");
		if (arr == null || arr.length <= 0) {
			return null;
		}
		for (int i = 0; i < arr.length; i++) {
			String item = arr[i];
			arr[i] = StringUtils.capitalize(item);
			
		}

		return StringUtils.join(arr, "");
	}
	
	/**
	 * 根据表明获取实体名
	 * @param tableName
	 */
	public static String getDTONameByTableName(String tableName) {
		if(StringUtils.isEmpty(tableName)) {
			return tableName;
		}
		tableName = tableName.trim().toLowerCase();
		String[] arr = StringUtils.split(tableName, "_");
		if (arr == null || arr.length <= 0) {
			return null;
		}
		for (int i = 0; i < arr.length; i++) {
			String item = arr[i];
			arr[i] = StringUtils.capitalize(item);
			
		}
		return StringUtils.join(arr, "") + "DTO";
	}
	
	/**
	 * 根据表明获取实体名
	 * @param tableName
	 */
	public static String getFieldNameByColumnName(String columnName) {
		if(StringUtils.isEmpty(columnName)) {
			return columnName;
		}
		columnName = columnName.trim().toLowerCase();
		String[] arr = StringUtils.split(columnName, "_");
		if (arr == null || arr.length <= 0) {
			return null;
		}
		for (int i = 0; i < arr.length; i++) {
			String item = arr[i];
			if (i > 0) {
				arr[i] = StringUtils.capitalize(item);
			}
		}

		return StringUtils.join(arr, "");
	}
	
	public static String lowerCaseFirstChar(String str) {
		if (StringUtils.isEmpty(str)) {
			return str;
		}
		return str.substring(0, 1).toLowerCase() + str.substring(1);
	}
	
	
	public static void main(String[] args) {
		System.out.println(getEntityNameByTableName("Td_cate_PUB"));
		System.out.println(getFieldNameByColumnName("Td_cate_PUB"));
//		System.out.println(lowerCaseFirstChar("TABC_cate_PUB"));
	}
}
